<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./js/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-focus>
        <h2 v-my-demo="title">我的第一个自定义指令</h2>
        <h1 v-my-vshow:title="flag">我的vshow</h1>
        <button v-my-on:click.stop="changeFlag">点击切换</button>
    </div>
</body>
<script>
    Vue.directive('focus', {
        inserted(el) {
            el.focus()
        }
    })
    Vue.directive('myDemo', {
        bind(el, binding) {
            console.log(binding)
            el.style.fontSize = "30px";
            el.style.color = "red";

        }
    })
    Vue.directive('myVshow', {
        bind(el, bingding) {
            el.style.display = bingding.value ? 'block' : 'none';
            console.log(bingding)
        },
        update(el, bingding) {
            el.style.display = bingding.value ? 'block' : 'none';
            console.log(bingding.value, "update", el)
            console.log(bingding)
        }
    })
    Vue.directive('myOn', {
        bind(el, binding) {
            el.addEventListener(binding.arg, binding.value, binding.modifiers.stop)
            console.log(binding, "on")
        }
    })
    const vm = new Vue({
        el: "#app",
        data: {
            title: "学好自定义指令",
            flag: true
        },
        methods: {
            changeFlag() {
                this.flag = !this.flag;
            }
        }
    })
</script>

</html>